package ${package.Entity};

<#if hasEnum>
import com.baomidou.mybatisplus.annotation.EnumValue;
</#if>
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;

<#list table.importPackages as pkg>
import ${pkg};
</#list>

<#if hasJson>
<#--import com.jxpanda.commons.base.EntityJsonTypeHandler;-->
import ${jsonTypeHandler};
</#if>
<#list injectPackage as pkg>
import ${pkg};
</#list>

<#if swagger>
import io.swagger.v3.oas.annotations.media.Schema;
</#if>

<#if entityLombokModel>
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
    <#if hasEnum>
import lombok.AllArgsConstructor;
    </#if>
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
</#if>


/**
 * ${table.comment!}
 *
 * @author ${author}
 * @since ${date}
 */
<#if entityLombokModel>
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@Accessors(chain = true)
</#if>
<#if hasJson>
@TableName(value = "`${table.name}`", autoResultMap = true)
<#else>
@TableName("`${table.name}`")
</#if>
<#if swagger>
@Schema(title = "${entity}对象", description = "${table.comment!}")
</#if>
<#if superEntityClass??>
public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
<#elseif activeRecord>
public class ${entity} extends Model<${entity}> {
<#else>
public class ${entity} implements Serializable {
</#if>
<#if entitySerialVersionUID>

    private static final long serialVersionUID = 1L;
</#if>
<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field>

    <#if field.keyFlag>
        <#assign keyPropertyName="${field.propertyName}"/>
    </#if>
    <#if field.keyFlag>
        <#-- 主键 -->
        <#if field.keyIdentityFlag>
    @TableId(value = "${field.name}", type = IdType.AUTO)
        <#elseif idType??>
    @TableId(value = "${field.name}", type = IdType.${idType})
        <#elseif field.convert>
    @TableId("${field.name}")
        </#if>
        <#-- 普通字段 -->
    <#elseif field.fill??>
    <#-- -----   存在字段填充设置   ----->
        <#if field.convert>
    @TableField(value = "`${field.name}`", fill = FieldFill.${field.fill})
            <#else>
    @TableField(fill = FieldFill.${field.fill})
        </#if>
    <#elseif json?? && json[field.name]??>
    @TableField(value = "`${field.name}`", typeHandler = EntityJsonTypeHandler.class, javaType = true)
    <#else>
    @TableField("`${field.name}`")
    </#if>
    <#-- 乐观锁注解 -->
    <#if (versionFieldName!"") == field.name>
    @Version
    </#if>
    <#-- 逻辑删除注解 -->
    <#if (logicDeleteFieldName!"") == field.name>
    @TableLogic
    </#if>
    <#if field.comment!?length gt 0>
        <#if swagger>
    @Schema(description = "${field.comment}")
        <#else>
    /**
     * ${field.comment}
     */
        </#if>
    </#if>
    <#if enum?? && enum[field.name]??>
    private ${enum[field.name].fieldType} ${field.propertyName};
        <#elseif json?? && json[field.name]??>
    private ${json[field.name].javaType} ${field.propertyName};
        <#else >
    private ${field.propertyType} ${field.propertyName};
    </#if>
</#list>

<#------------  END 字段循环遍历  ---------->
<#if enum??>
    <#list enum as k,v>
        <#if !v.redundancy>
    @Getter
    @AllArgsConstructor
    public enum ${v.fieldType} {
        /**
         * 未知
         */
        UNKNOWN(0, "未知"),
        <#list v.values as value>
        /**
         * ${value.description}
         */
        ${value.field}(${value.value}, "${value.description}")<#if value_has_next>,<#else>;</#if>
        </#list>

        @EnumValue
        private final Integer code;
        private final String description;
    }

        </#if>
    </#list>
</#if>
<#if json??>
    <#list json as k,v>
        <#if v.generate>
    @Getter
    @Setter
    @NoArgsConstructor
    @Accessors(chain = true)
    public static class ${v.className} {
    <#list v.fields as field>
        <#if swagger>
        @Schema(description = "${field.comment}")
        <#else>
        /**
         * ${field.comment}
         */
        </#if>
        private ${field.type} ${field.name};
     </#list>
    }

        </#if>
    </#list>
</#if>
<#if !entityLombokModel>
    <#list table.fields as field>
        <#if field.propertyType == "boolean">
            <#assign getprefix="is"/>
        <#else>
            <#assign getprefix="get"/>
        </#if>
    public ${field.propertyType} ${getprefix}${field.capitalName}() {
        return ${field.propertyName};
    }

    <#if entityBuilderModel>
    public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
    <#else>
    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
    </#if>
        this.${field.propertyName} = ${field.propertyName};
        <#if entityBuilderModel>
        return this;
        </#if>
    }
    </#list>
</#if>
<#if entityColumnConstant>
    <#list table.fields as field>
    public static final String ${field.name?upper_case} = "`${field.name}`";
    </#list>

</#if>
<#if activeRecord>
    @Override
    protected Serializable pkVal() {
    <#if keyPropertyName??>
        return this.${keyPropertyName};
    <#else>
        return null;
    </#if>
    }

</#if>
<#if !entityLombokModel>
    @Override
    public String toString() {
        return "${entity}{" +
    <#list table.fields as field>
        <#if field_index==0>
            "${field.propertyName}=" + ${field.propertyName} +
        <#else>
            ", ${field.propertyName}=" + ${field.propertyName} +
        </#if>
    </#list>
        "}";
    }
</#if>
}
